package com.hsav.kcxb.view;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;

import com.hsav.kcxb.R;
import com.hsav.kcxb.adapter.ContributeAdapter;
import com.hsav.kcxb.bean.ContributeBean;

import java.util.ArrayList;

/**
 * Created by zhao on 2017/2/5.
 */

public class ContributeView extends LinearLayout {

    private final Context mContext;

    public ContributeView(Context context) {
        this(context,null);
    }

    public ContributeView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public ContributeView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
        initView();
    }

    private void initView() {
        ListView listView = new ListView(mContext);
        LinearLayout.LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.leftMargin=10;
        layoutParams.topMargin = 10;
        listView.setLayoutParams(layoutParams);
        Drawable divieDrawable = mContext.getResources().getDrawable(R.color.color_gray);
        listView.setDivider(divieDrawable);
        listView.setDividerHeight(4);

//        View rootView = LayoutInflater.from(mContext).inflate(R.layout.layout_contribute,this);
//        ListView listView = (ListView)rootView.findViewById(R.id.list_contribute);

        ArrayList<ContributeBean> contributeBeenList = new ArrayList<>();
        contributeBeenList.add(new ContributeBean(1,"haha",3,"pic"));
        contributeBeenList.add(new ContributeBean(1,"haha",3,"pic"));
        contributeBeenList.add(new ContributeBean(1,"haha",3,"pic"));
        contributeBeenList.add(new ContributeBean(1,"haha",3,"pic"));
        contributeBeenList.add(new ContributeBean(1,"haha",3,"pic"));
        contributeBeenList.add(new ContributeBean(1,"haha",3,"pic"));
        contributeBeenList.add(new ContributeBean(1,"haha",3,"pic"));
        contributeBeenList.add(new ContributeBean(1,"haha",3,"pic"));
        contributeBeenList.add(new ContributeBean(1,"haha",3,"pic"));

        ContributeAdapter contributeAdapter = new ContributeAdapter(mContext);
        listView.setAdapter(contributeAdapter);
        this.addView(listView);
    }
}
